<!-- browers -->
<template>
  <div class="indexcontent">
    <pageHeader ref="header"></pageHeader>
    <div class="section">
      <div @click="GetVersion_OnClick">test version</div>
      <div @click="SelectCertificateOnClick">SelectCertificateOnClick</div>
      <input type="text" id="SelectCertResult">
    </div>
    <pageFooter/>
  </div>
</template>

<script>

  import { mapMutations } from 'vuex'
  import pageHeader from '@/components/pageHeader'
  import pageFooter from '@/components/pageFooter'

  var CryptoAgent = "";
  (function(){
      console.log('jiazai')
      try {
          var eDiv = document.createElement("div");
          if (navigator.appName.indexOf("Internet") >= 0 || navigator.appVersion.indexOf("Trident") >= 0) {
              if (window.navigator.cpuClass == "x86") {
                  eDiv.innerHTML = "<object id=\"CryptoAgent\" codebase=\"CryptoKit.Paperless.x86.cab\" classid=\"clsid:B64B695B-348D-400D-8D58-9AAB1DA5851A\" ></object>";
              }
              else {
                  eDiv.innerHTML = "<object id=\"CryptoAgent\" codebase=\"CryptoKit.Paperless.x64.cab\" classid=\"clsid:8BF7E683-630E-4B59-9E61-C996B671EBDF\" ></object>";
              }
          }
          else {
              eDiv.innerHTML = "<embed id=\"CryptoAgent\" type=\"application/npCryptoKit.Paperless.x86\" style=\"height: 0px; width: 0px\">";
          }
          document.body.appendChild(eDiv);
      }
      catch (e) {
          alert(e);
          return;
      }
      CryptoAgent = document.getElementById("CryptoAgent");
  })()

  export default {
    components: {
      pageHeader,
      pageFooter
    },

    data() {
      return {

      }
    },
    created() {
        this.GetVersion_OnClick()
    },
    computed: {},

    mounted() {

    },

    methods: {
        GetVersion_OnClick() {
            var version = "";
            try {
                version = CryptoAgent.GetVersion();
                alert(version);
            }
            catch (e) {
                var strErrorDsc = CryptoAgent.GetLastErrorDesc();
                alert(strErrorDsc);
            }
        },
        SelectCertificateOnClick() {
            try {
                document.getElementById("SelectCertResult").value = "";

                var subjectDNFilter = "";
                var issuerDNFilter = "";
                var serialNumFilter = "";
                var cspName = "";
                var bSelectCertResult = "";

                bSelectCertResult = CryptoAgent.SelectCertificate(subjectDNFilter, issuerDNFilter, serialNumFilter, cspName);
                // Opera浏览器，NPAPI函数执行结果为false时，不能触发异常，需要自己判断返回值。
                if (!bSelectCertResult) {
                    var errorDesc = CryptoAgent.GetLastErrorDesc();
                    alert(errorDesc);
                    return;
                }
                document.getElementById("SelectCertResult").value = bSelectCertResult;
                console.log(bSelectCertResult)
            }

            catch (e) {
                var errorDesc = CryptoAgent.GetLastErrorDesc();
                alert(errorDesc);
            }
        },
    }
  }
</script>
<style scoped>

</style>
